package com.ruoyi.system.service.impl;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.domain.SysOperApiLog;
import com.ruoyi.system.mapper.SysOperApiLogMapper;
import com.ruoyi.system.service.ISysOperApiLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 自定义操作日志记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-16
 */
@Slf4j
@Service
public class SysOperApiLogServiceImpl extends ServiceImpl<SysOperApiLogMapper, SysOperApiLog> implements ISysOperApiLogService {


    @Override
    public List<SysOperApiLog> list(String schoolId, String title, Integer operatorType, Integer businessType, String operName, String startTime, String endTime,String userId) {
        return this.list(Wrappers.<SysOperApiLog>lambdaQuery().eq(StringUtils.isNotEmpty(schoolId),SysOperApiLog::getSchoolId,schoolId)
                .like(StringUtils.isNotEmpty(title),SysOperApiLog::getTitle,title)
                .eq(Objects.nonNull(operatorType),SysOperApiLog::getOperatorType,operatorType)
                .eq(Objects.nonNull(businessType),SysOperApiLog::getBusinessType,businessType)
                .like(StringUtils.isNotEmpty(operName),SysOperApiLog::getOperName,operName)
                .eq(StringUtils.isNotEmpty(userId),SysOperApiLog::getUserId,userId)
                .apply(StringUtils.isNotEmpty(startTime),
                        "date_format(oper_time,'%Y-%m-%d') >= date_format('" + startTime+ "','%Y-%m-%d')")
                .apply(StringUtils.isNotEmpty(endTime),
                        "date_format(oper_time,'%Y-%m-%d') <= date_format('" + endTime+ "','%Y-%m-%d')")
                .orderByDesc(SysOperApiLog::getOperTime));
    }
}
